@extends('backstage.layout.master')
@section('title', '订单列表')
@section('style')
        <!-- page specific plugin styles -->
<meta name="_token" content="{{csrf_token()}}"/>
<link rel="stylesheet" href="/assets/css/jquery-ui-1.10.3.custom.min.css"/>
<link rel="stylesheet" href="/assets/css/chosen.css"/>
<link rel="stylesheet" href="/assets/css/datepicker.css"/>
<link rel="stylesheet" href="/assets/css/bootstrap-timepicker.css"/>
<link rel="stylesheet" href="/assets/css/daterangepicker.css"/>
<link rel="stylesheet" href="/assets/css/colorpicker.css"/>
<!-- fonts -->
<style>
    #outExcel{
        top:40px;
    }
    select{
        width:113px;
    }
    .order_count {
        font-size: 19px;
    }
</style>
@stop
@section('script')
    <script src="backstage/assets/js/date-time/bootstrap-datepicker.min.js"></script>
    <script src="backstage/assets/js/date-time/bootstrap-timepicker.min.js"></script>
    <script src="backstage/assets/js/date-time/moment.min.js"></script>
    <script src="backstage/assets/js/date-time/daterangepicker.min.js"></script>
    <script type="text/javascript">
        $('input[name=date-range-picker]').daterangepicker().prev().on(ace.click_event, function(){
                $(this).next().focus();
         });
        function findOrderBy(){
            var str = "";
            var column1 = $("#column1 option:selected").val();
            var value1  = $("#"+column1).val();
            if(value1 != "" && value1 != undefined && str.length>0){
                str    += "&"+column1+"="+value1;
            }else if(value1 != "" && value1 != undefined && str.length==0){
                str    += column1+"="+value1;
            }

            var column2 = $("#column2 option:selected").val();
            var value2  = $("#"+ column2 + " option:selected").val();
            if(value2 != "" && value2 != undefined && str.length>0){
                str    += "&"+column2+"="+value2;
            }else if(value2 != "" && value2 != undefined && str.length==0){
                str    += column2+"="+value2;
            }

            var column3 = $("#column3 option:selected").val();
            var value3  = $("#"+column3).val();
            if(value3 != "" && value3 != undefined && str.length>0){
                str    += "&"+column3+"="+value3;
            }else if(value3 != "" && value3 != undefined && str.length==0){
                str    += column3+"="+value3;
            }

            var column4 = $("#column4 option:selected").val();
            var value4  = $("#"+column4).val();
            if(value4 != "" && value4 != undefined && str.length>0){
                str    += "&"+column4+"="+value4;
            }else if(value4 != "" && value4 != undefined && str.length==0){
                str    += column4+"="+value4;
            }

            var column5 = $("#column5 option:selected").val();
            var value5  = $("#"+column5 + " option:selected").val();
            if(value5 != "" && value5 != undefined && str.length>0){
                str    += "&"+column5+"="+value5;
            }else if(value5 != "" && value5 != undefined && str.length==0){
                str    += column5+"="+value5;
            }

            var column6 = $("#column6 option:selected").val();
            var value6  = $("#"+column6 + " option:selected").val();
            if(value6 != "" && value6 != undefined && str.length>0){
                str    += "&"+column6+"="+value6;
            }else if(value6 != "" && value6 != undefined && str.length==0){
                str    += column6+"="+value6;
            }

            var column7 = $("#column7 option:selected").val();
            var value7 = $("#"+column7 + " option:selected").val();
            if(value7 != "" && value7 != undefined && str.length>0){
                str    += "&"+column7+"="+value7;
            }else if(value7 != "" && value7 != undefined && str.length==0){
                str    += column7+"="+value7;
            }

            var column8 = $("#column8 option:selected").val();
            var value8 = $("#"+column8).val();
            if(value8 != "" && value8 != undefined && str.length>0){
                str    += "&"+column8+"="+value8;
            }else if(value8 != "" && value8 != undefined && str.length==0){
                str    += column8+"="+value8;
            }

            var column9 = $("#column9 option:selected").val();
            var value9 = $("#"+column9).val();
            if(value9 != "" && value9 != undefined && str.length>0){
                str    += "&"+column9+"="+value9;
            }else if(value9 != "" && value9 != undefined && str.length==0){
                str    += column9+"="+value9;
            }

            var column10 = $("#column10 option:selected").val();
            var value10 = $("#"+column10 + ' option:selected').val();
            if(value10 != "" && value10 != undefined && str.length>0){
                str    += "&"+column10+"="+value10;
            }else if(value10 != "" && value10 != undefined && str.length==0){
                str    += column10+"="+value10;
            }

            //alert(str.length);
            window.location.href="/backstage/order/order-list?"+str;
        }


        function createExcel(){
            var value   = $("#outExcel").attr("data");
            swal('订单导出中','请勿重复点击导出订单','warning');
            $.ajax({
                url:'/backstage/order/create-excel?'+value,
                type:'get',
                data:{},
                datatype:'json',
                success:function(re){
                    if(re.state==undefined){
                        re = eval(re);
                    }
                    if(re.state=='M00000'){
                        window.location.href=re.result.url;
                        return;
                    }
                    swal(re.message,'','warning');
                    return;
                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');
                }
            });
        }

        function change_state(th){
            var state           = $("#"+th+" option:selected").val();

            $.ajax({
                url:"/backstage/order/upd-order-state",
                type:"post",
                data:{"state":state,"order_id":th},
                datatype:'json',
                success:function(re){
                    if(re.state=="M00000"){
                        swal(re.message,'','success');
                        return;
                    }
                    swal(re.message,'','warning');
                    return;

                },
                error:function(){
                    swal('系统繁忙','请稍后重试','warning');return;
                }
            });
        }
    </script>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="#">主页</a>
            </li>

            <li class="active">
                <a href="backstage/order/order-list">订单</a>
            </li>
            <li>
                订单列表
            </li>
        </ul><!-- .breadcrumb -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                订单
                <small>
                    <i class="icon-double-angle-right"></i>
                    订单列表
                </small>
            </h1>
            <div class="nav-search" id="nav-search">

                <button id="outExcel" class="btn" onclick="createExcel();" data="{{isset($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:''}}">
                    导出订单
                </button>
                <a href="" id="downExcel" style="display:none;" download="">
                    下载
                </a>

            </div><!-- #nav-search -->
        </div>
        <div class="row">
            <div class="nav-search col-xs-12" style="position: static;height: 50px;" id="nav-search">
                <select id="column1">
                    <option value ="order_id">订单编号</option>
                </select>
                <span class="input-icon" style="width: 209px;">
                    <input type="text" class="form-control" id="order_id" autocomplete="off"
                    value="{{isset($_GET['order_id'])&&$_GET['order_id']!=''?$_GET['order_id']:''}}"/>
                </span>
                &nbsp
                <select id="column2">
                    <option value ="state">状态</option>
                </select>
                <span class="input-icon">
                    <select id="state"  style="width:209px;">
                        <option value =""></option>
                        <option value ='{"is_cancel":0,"state":1}' @if(isset($_GET['state']) && $_GET['state'] == '{"is_cancel":0,"state":1}')
                        selected ="selected"@endif>
                        等待支付
                        </option>
                        <option value ='{"is_cancel":0,"state":2}' @if(isset($_GET['state']) && $_GET['state'] == '{"is_cancel":0,"state":2}')
                        selected ="selected"@endif>
                        等待发货
                        </option>
                        <option value ='{"is_cancel":0,"state":3}' @if(isset($_GET['state']) && $_GET['state'] == '{"is_cancel":0,"state":3}')
                        selected ="selected"@endif>
                        等待签收
                        </option>
                        <option value ='{"is_cancel":0,"state":4}' @if(isset($_GET['state']) && $_GET['state'] == '{"is_cancel":0,"state":4}')
                        selected ="selected"@endif>
                        已完成
                        </option>
                        <option value ='{"is_cancel":1}' @if(isset($_GET['state']) && $_GET['state'] == '{"is_cancel":1}')
                        selected ="selected"@endif>
                        已取消
                        </option>
                        <option value ='{"is_cancel":0,"state":0}' @if(isset($_GET['state']) && $_GET['state'] == '{"is_cancel":0,"state":0}')
                        selected ="selected"@endif>
                        已删除
                        </option>
                    </select>
                </span>

            </div><!-- #nav-search -->
            <div class="nav-search col-xs-12" style="position: static;height: 50px;" id="nav-search">
                <select id="column3">
                    <option value ="consignee">收货人</option>
                </select>
                <span class="input-icon" style="width: 209px;">
                    <input type="text" class="form-control" id="consignee" autocomplete="off"
                    value="{{isset($_GET['consignee'])&&$_GET['consignee']!=''?$_GET['consignee']:''}}"/>
                </span>
                &nbsp
                <select id="column4">
                    <option value ="phone">收货人手机号</option>
                </select>
                <span class="input-icon" style="width: 209px;">
                    <input type="text" class="form-control" id="phone" autocomplete="off"
                    value="{{isset($_GET['phone'])&&$_GET['phone']!=''?$_GET['phone']:''}}" maxlength="11"/>
                </span>

            </div><!-- #nav-search -->
            <div class="nav-search col-xs-12" style="position: static;height: 50px;" id="nav-search">
                <select id="column5">
                    <option value ="platform">渠道</option>
                </select>
                <span class="input-icon">
                    <select id="platform"  style="width:209px;">
                        <option value =""></option>
                        <option value ="IOS" @if(isset($_GET['platform'])&&$_GET['platform']=='IOS') selected="selected" @endif >IOS</option>
                        <option value ="Android" @if(isset($_GET['platform'])&&$_GET['platform']=='Android') selected="selected" @endif >Android</option>
                        <option value ="Web" @if(isset($_GET['platform'])&&$_GET['platform']=='Web') selected="selected" @endif >Web</option>
                        <option value ="Backstage" @if(isset($_GET['platform'])&&$_GET['platform']=='Backstage') selected="selected" @endif >后台</option>
                        <option value ="活动" @if(isset($_GET['platform'])&&$_GET['platform']=='活动') selected="selected" @endif >活动</option>
                    </select>
                </span>
                &nbsp
                <select id="column6">
                    <option value ="pay_type">支付类型</option>
                </select>
                <span class="input-icon">
                    <select id="pay_type"  style="width:209px;">
                        <option value =""></option>
                        <option value ="1" @if(isset($_GET['pay_type'])&&$_GET['pay_type']==1) selected="selected" @endif >微信</option>
                        <option value ="2" @if(isset($_GET['pay_type'])&&$_GET['pay_type']==2) selected="selected" @endif >支付宝</option>
                        <option value ="3" @if(isset($_GET['pay_type'])&&$_GET['pay_type']==3) selected="selected" @endif >优惠券</option>
                    </select>
                </span>
            </div>
            <div class="nav-search col-xs-12" style="position: static;height: 50px;" id="nav-search">
                <select id="column7">
                    <option value ="express_id">配送方式</option>
                </select>
                <span class="input-icon">
                    <select id="express_id"  style="width:209px;">
                        <option value =""></option>
                        @if(isset($express))
                        @foreach($express as $exp)
                        <option value="{{isset($exp->express_id) ? $exp->express_id : ''}}"
                        @if(isset($_GET['express_id']) && $_GET['express_id'] == $exp->express_id) selected="selected" @endif>
                            {{isset($exp->express_name) ? $exp->express_name : ''}}
                        </option>
                        @endforeach
                        @endif
                    </select>
                </span>
                &nbsp
                <select id="column8">
                    <option value ="time_range">时间段</option>
                </select>
                <span class="input-icon" style="width: 209px;">
                    <input class="form-control" style="cursor:pointer;" type="text" name="date-range-picker" readonly id="time_range"
                    value="{{isset($_GET['time_range'])&&$_GET['time_range']!=''?$_GET['time_range']:''}}"/>
                </span>
            </div>
            <div class="nav-search col-xs-12" style="position: static;height: 50px;" id="nav-search">

                <select id="column9">
                    <option value ="worksheet_id">工单号</option>
                </select>
                <span class="input-icon" style="width: 209px;">
                    <input class="form-control" id="worksheet_id"
                    value="{{isset($_GET['worksheet_id'])&&$_GET['worksheet_id']!=''?$_GET['worksheet_id']:''}}"/>
                </span>
                &nbsp
                <select id="column10">
                    <option value ="channel_id">活动</option>
                </select>
                <span class="input-icon" style="width: 209px;">
                    <select id="channel_id"  style="width:209px;">
                        <option value =""></option>
                        <option value ="kanjia20170310"
                        @if(isset($_GET['channel_id']) && $_GET['channel_id'] == 'kanjia20170310') selected="selected" @endif>
                            砍价活动(20170310)
                        </option>
                        <option value ="septwolves20170316"
                        @if(isset($_GET['channel_id']) && $_GET['channel_id'] == 'septwolves20170316') selected="selected" @endif>
                            七匹狼活动(20170316)
                        </option>
                    </select>
                </span>
                <button class="btn" onclick="findOrderBy();" >
                    搜索
                </button>
            </div>
            <div class="nav-search col-xs-12" style="position: static;height: 50px;" id="nav-search">



            </div><!-- #nav-search -->
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="order_count">订单数量: <span>{{isset($orders) ? $orders->total() : 0}}</span></div>
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>订单编号</th>
                            <th>收货人</th>
                            <th>渠道</th>
                            <th>订单总金额</th>
                            <th>应付金额</th>
                            <th>下单时间</th>
                            <th>订单状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @if(!isset($orders)||count($orders)==0)
                        <tr class="">暂时没有可处理订单</tr>
                        @else
                        @foreach ($orders as $order)
                        <tr class="">
                            <td>{{isset($order->order_id)?$order->order_id:''}}</td>
                            <td>
                            {{isset($order->rece->consignee) ? $order->rece->consignee : ''}}[TEL:{{isset($order->rece->phone)?$order->rece->phone:''}}]
                            <br>
                            {{isset($order->rece->address) ? $order->rece->address : ''}}
                            </td>
                            <td>
                                {{isset($order->platform)?$order->platform:''}}
                            </td>
                            <td>
                                {{isset($order->total_price) ? $order->total_price : ''}}
                            </td>
                            <td>
                                {{isset($order->total_fee)?$order->total_fee:''}}
                            </td>

                            <td>
                                {{isset($order->created_at)?date('Y-m-d H:i:s',$order->created_at):''}}
                            </td>
                            <td>
                                @if($order->is_cancel==0&&$order->state==1)
                                    等待支付
                                @elseif($order->is_cancel==0&&$order->state==2)
                                    等待发货
                                @elseif($order->is_cancel==0&&$order->state==3)
                                    等待签收
                                @elseif($order->is_cancel==0&&$order->state==4)
                                    已完成
                                @elseif($order->is_cancel==1&&$order->state!=0)
                                    已取消
                                @elseif($order->state==0)
                                    已删除
                                @endif
                            </td>
                            <td>
                                <ul class="nav-pills" style="list-style-type:none">
                                    <li class="dropdown all-camera-dropdown">
                                        <a target="_blank" href="/backstage/order/order-detail?order_id={{$order->order_id}}">
                                            <span id="app_users_selections_contacts_1">查看</span>
                                        </a>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                        @endforeach
                        @endif
                        </tbody>
                    </table>
                </div>
                @if(!isset($orders))
                @else
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $orders->render(); ?>
                        </div>
                    </div>
                </div>
                @endif
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
